﻿namespace WMS6.SQLServerDAL
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Common;
    using System.Data.SqlClient;
    using WMS6.Common;
    using WMS6.DataEntity;
    using WMS6.DBUtility;
    using WMS6.IDAL;
    using WMS6.QueryEntity;

    public class TaskRuleDetailDA : ITaskRuleDetailDA
    {
        private string CREATED_BY = "@CREATED_BY";
        private string DESCR = "@DESCR";
        private string IS_ACTIVE = "@IS_ACTIVE";
        private string LINE_ID = "@LINE_ID";
        private string SQL_CHECK_TASK_RULE_DETAIL_ID_UNIQUE = " SELECT COUNT(1) FROM @_@TASK_RULE_DETAIL WHERE TASK_RULE_ID = @TASK_RULE_ID AND LINE_ID = @LINE_ID ";
        private string SQL_DELETE_ONE_TASK_RULE_DETAIL = " DELETE FROM @_@TASK_RULE_DETAIL WHERE TASK_RULE_ID = @TASK_RULE_ID AND LINE_ID = @LINE_ID ";
        private string SQL_DELETE_TASK_RULE_DETAIL = " DELETE FROM @_@TASK_RULE_DETAIL WHERE TASK_RULE_ID = @TASK_RULE_ID ";
        private string SQL_INSERT_TASK_RULE_DETAIL = " INSERT INTO @_@TASK_RULE_DETAIL ( WH_ID, TASK_RULE_ID, LINE_ID, TASK_STRATEGY, DESCR, TASK_TYPE, TASK_PICK_CODE, IS_ACTIVE, CREATED_BY, CREATED_DATE, UPDATED_BY, UPDATED_DATE) VALUES ( @WH_ID, @TASK_RULE_ID, @LINE_ID, @TASK_STRATEGY, @DESCR, @TASK_TYPE, @TASK_PICK_CODE, @IS_ACTIVE, @CREATED_BY, GETDATE(), @UPDATED_BY, GETDATE() )  ";
        private string SQL_SELECT_ALL_TASK_RULE_DETAIL = " SELECT TRD.ROWID, TRD.WH_ID, TRD.TASK_RULE_ID, TRD.LINE_ID, TRD.TASK_STRATEGY, TRD.DESCR, TRD.TASK_TYPE,T.[TEXT] AS TASK_TYPE_DESCR, TRD.TASK_PICK_CODE, TRD.IS_ACTIVE, TRD.TS, TRD.CREATED_BY, TRD.CREATED_DATE, TRD.UPDATED_BY, TRD.UPDATED_DATE   FROM  @_@TASK_RULE_DETAIL TRD LEFT JOIN @_@SYS_CODE_DETAIL SCD ON SCD.SYS_CODE = TRD.TASK_TYPE AND SCD.SYS_CODE_TYPE = 'TaskType' LEFT JOIN sysadm.TRANSLATION T ON 'TaskType.'+TRD.TASK_TYPE = T.ITEM_ID AND  T.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T.LANG+'-'+T.COUNTRY = @LANGUAGE ";
        private string SQL_UPDATE_TASK_RULE_DETAIL = " UPDATE @_@TASK_RULE_DETAIL SET WH_ID = @WH_ID, TASK_STRATEGY = @TASK_STRATEGY, DESCR = @DESCR, TASK_TYPE = @TASK_TYPE, TASK_PICK_CODE = @TASK_PICK_CODE, IS_ACTIVE = @IS_ACTIVE, UPDATED_BY = @UPDATED_BY, UPDATED_DATE = GETDATE() WHERE TASK_RULE_ID = @TASK_RULE_ID AND LINE_ID = @LINE_ID  ";
        private string TASK_PICK_CODE = "@TASK_PICK_CODE";
        private string TASK_RULE_ID = "@TASK_RULE_ID";
        private string TASK_STRATEGY = "@TASK_STRATEGY";
        private string TASK_TYPE = "@TASK_TYPE";
        private string TS = "@TS";
        private string UPDATED_BY = "@UPDATED_BY";
        private string WH_ID = "@WH_ID";

        public bool CheckTaskRuleDetailIDUnique(string taskRuleID, string lineID, string whLoginID)
        {
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@TASK_RULE_ID", taskRuleID), new SqlParameter("@LINE_ID", lineID) };
            return (DBHelper.ExecuteScalar(CommandType.Text, this.SQL_CHECK_TASK_RULE_DETAIL_ID_UNIQUE.Replace("@_@", whLoginID), paras).ToString() == "1");
        }

        public bool CheckTaskRuleDetailIDUnique(DataBase dataBase, DbTransaction tran, string taskRuleID, string lineID, string whLoginID)
        {
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@TASK_RULE_ID", taskRuleID), new SqlParameter("@LINE_ID", lineID) };
            return (dataBase.ExecuteScalar(tran, CommandType.Text, this.SQL_CHECK_TASK_RULE_DETAIL_ID_UNIQUE.Replace("@_@", whLoginID), paras).ToString() == "1");
        }

        public int DeleteTaskRuleDetail(List<string> taskRuleDetailID, List<string> whLoginID)
        {
            int result = 0;
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    for (int j = 0; j < taskRuleDetailID.Count; j++)
                    {
                        SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@TASK_RULE_ID", taskRuleDetailID[j]) };
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_DELETE_TASK_RULE_DETAIL.Replace("@_@", whLoginID[i]), paras);
                    }
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int DeleteTaskRuleDetail(List<string> taskRuleID, List<string> lineID, List<string> whLoginID)
        {
            int result = 0;
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    string sqlStr = this.SQL_DELETE_ONE_TASK_RULE_DETAIL.Replace("@_@", whLoginID[i]);
                    for (int j = 0; j < taskRuleID.Count; j++)
                    {
                        SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@TASK_RULE_ID", taskRuleID[j]), new SqlParameter("@LINE_ID", lineID[j]) };
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, sqlStr, paras);
                    }
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int DeleteTaskRuleDetail(DataBase dataBase, DbTransaction tran, List<string> taskRuleDetailID, List<string> whLoginID)
        {
            int result = 0;
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    for (int j = 0; j < taskRuleDetailID.Count; j++)
                    {
                        SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@TASK_RULE_ID", taskRuleDetailID[j]) };
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_DELETE_TASK_RULE_DETAIL.Replace("@_@", whLoginID[i]), paras);
                    }
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        public int DeleteTaskRuleDetail(DataBase dataBase, DbTransaction tran, List<string> taskRuleID, List<string> lineID, List<string> whLoginID)
        {
            int result = 0;
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    string sqlStr = this.SQL_DELETE_ONE_TASK_RULE_DETAIL.Replace("@_@", whLoginID[i]);
                    for (int j = 0; j < taskRuleID.Count; j++)
                    {
                        SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@TASK_RULE_ID", taskRuleID[j]), new SqlParameter("@LINE_ID", lineID[j]) };
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, sqlStr, paras);
                    }
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        public DataSet GetAllTaskRuleDetail(string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = this.SQL_SELECT_ALL_TASK_RULE_DETAIL.Replace("@_@", whLoginID);
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@LANGUAGE", pubParasInfo.UserLanguage), new SqlParameter("@USER_ID", pubParasInfo.UserID) };
            return DBHelper.ExecuteDataSet(CommandType.Text, sql, paras);
        }

        public DataSet GetAllTaskRuleDetail(DataBase dataBase, DbTransaction tran, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = this.SQL_SELECT_ALL_TASK_RULE_DETAIL.Replace("@_@", whLoginID);
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@LANGUAGE", pubParasInfo.UserLanguage), new SqlParameter("@USER_ID", pubParasInfo.UserID) };
            return dataBase.ExecuteDataSet(tran, CommandType.Text, sql, paras);
        }

        public TaskRuleDetailInfo GetTaskRuleDetailByID(string taskruledetailID, string lineID, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = this.SQL_SELECT_ALL_TASK_RULE_DETAIL.Replace("@_@", whLoginID) + " WHERE TASK_RULE_ID = @TASK_RULE_ID AND LINE_ID = @LINE_ID ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@TASK_RULE_ID", taskruledetailID), new SqlParameter("@LANGUAGE", pubParasInfo.UserLanguage), new SqlParameter("@LINE_ID", lineID) };
            TaskRuleDetailInfo taskRuleDetail = null;
            using (IDataReader reader = DBHelper.ExecuteReader(CommandType.Text, sql, paras))
            {
                if (reader.Read())
                {
                    taskRuleDetail = new TaskRuleDetailInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["TASK_RULE_ID"].ToString(), (reader["LINE_ID"].ToString() != "") ? int.Parse(reader["LINE_ID"].ToString()) : 0, reader["TASK_STRATEGY"].ToString(), reader["DESCR"].ToString(), reader["TASK_TYPE"].ToString(), reader["TASK_TYPE_DESCR"].ToString(), reader["TASK_PICK_CODE"].ToString(), reader["IS_ACTIVE"].ToString(), (byte[]) reader["TS"], reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : new DateTime(), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : new DateTime());
                }
            }
            return taskRuleDetail;
        }

        public TaskRuleDetailInfo GetTaskRuleDetailByID(DataBase dataBase, DbTransaction tran, string taskruledetailID, string lineID, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = this.SQL_SELECT_ALL_TASK_RULE_DETAIL.Replace("@_@", whLoginID) + " WHERE TASK_RULE_ID = @TASK_RULE_ID AND LINE_ID = @LINE_ID  ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@TASK_RULE_ID", taskruledetailID), new SqlParameter("@LANGUAGE", pubParasInfo.UserLanguage), new SqlParameter("@LINE_ID", lineID) };
            TaskRuleDetailInfo taskRuleDetailInfo = null;
            IDataReader reader = dataBase.ExecuteReader(tran, CommandType.Text, sql, paras);
            if (reader.Read())
            {
                taskRuleDetailInfo = new TaskRuleDetailInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["TASK_RULE_ID"].ToString(), (reader["LINE_ID"].ToString() != "") ? int.Parse(reader["LINE_ID"].ToString()) : 0, reader["TASK_STRATEGY"].ToString(), reader["DESCR"].ToString(), reader["TASK_TYPE"].ToString(), reader["TASK_TYPE_DESCR"].ToString(), reader["TASK_PICK_CODE"].ToString(), reader["IS_ACTIVE"].ToString(), (byte[]) reader["TS"], reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : new DateTime(), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : new DateTime());
            }
            if (!reader.IsClosed)
            {
                reader.Close();
            }
            return taskRuleDetailInfo;
        }

        public DataSet GetTaskRuleDetailByQueryList(List<string> sqlWhere, TaskRuleDetailQueryEntity taskruledetailQuery, string whLoginID, PubParasInfo pubParasInfo)
        {
            string temp = this.SQL_SELECT_ALL_TASK_RULE_DETAIL.Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    temp = temp + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    temp = temp + " AND " + sqlWhere[i].ToString();
                }
            }
            if (!taskruledetailQuery.IsGetAll)
            {
                temp = PagingHelper.GetPagingSQL(temp, taskruledetailQuery.CurrentPage, taskruledetailQuery.PageSize, taskruledetailQuery.SortField, taskruledetailQuery.SortDirection).Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''");
            }
            else
            {
                temp = temp.Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'");
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, temp);
        }

        public DataSet GetTaskRuleDetailByQueryList(DataBase dataBase, DbTransaction tran, List<string> sqlWhere, TaskRuleDetailQueryEntity taskruledetailQuery, string whLoginID, PubParasInfo pubParasInfo)
        {
            string temp = this.SQL_SELECT_ALL_TASK_RULE_DETAIL.Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    temp = temp + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    temp = temp + " AND " + sqlWhere[i].ToString();
                }
            }
            if (!taskruledetailQuery.IsGetAll)
            {
                temp = PagingHelper.GetPagingSQL(temp, taskruledetailQuery.CurrentPage, taskruledetailQuery.PageSize, taskruledetailQuery.SortField, taskruledetailQuery.SortDirection).Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''");
            }
            else
            {
                temp = temp.Replace("@LANGUAGE", "'" + pubParasInfo.UserLanguage + "'");
            }
            return dataBase.ExecuteDataSet(tran, CommandType.Text, temp);
        }

        public List<TaskRuleDetailInfo> GetTaskRuleDetailListByID(string taskRuleID, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = this.SQL_SELECT_ALL_TASK_RULE_DETAIL.Replace("@_@", whLoginID) + " WHERE TASK_RULE_ID = @TASK_RULE_ID  ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@TASK_RULE_ID", taskRuleID), new SqlParameter("@LANGUAGE", pubParasInfo.UserLanguage) };
            List<TaskRuleDetailInfo> taskRuleDetailInfos = new List<TaskRuleDetailInfo>();
            TaskRuleDetailInfo taskRuleDetail = null;
            using (IDataReader reader = DBHelper.ExecuteReader(CommandType.Text, sql, paras))
            {
                while (reader.Read())
                {
                    DateTime CS00002;
                    taskRuleDetail = new TaskRuleDetailInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["TASK_RULE_ID"].ToString(), (reader["LINE_ID"].ToString() != "") ? int.Parse(reader["LINE_ID"].ToString()) : 0, reader["TASK_STRATEGY"].ToString(), reader["DESCR"].ToString(), reader["TASK_TYPE"].ToString(), reader["TASK_TYPE_DESCR"].ToString(), reader["TASK_PICK_CODE"].ToString(), reader["IS_ACTIVE"].ToString(), (byte[]) reader["TS"], reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : (CS00002 = new DateTime()), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : (CS00002 = new DateTime()));
                    taskRuleDetailInfos.Add(taskRuleDetail);
                }
            }
            return taskRuleDetailInfos;
        }

        public List<TaskRuleDetailInfo> GetTaskRuleDetailListByID(DataBase dataBase, DbTransaction tran, string taskRuleID, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = this.SQL_SELECT_ALL_TASK_RULE_DETAIL.Replace("@_@", whLoginID) + " WHERE TASK_RULE_ID = @TASK_RULE_ID  ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@TASK_RULE_ID", taskRuleID), new SqlParameter("@LANGUAGE", pubParasInfo.UserLanguage) };
            List<TaskRuleDetailInfo> taskRuleDetailInfos = new List<TaskRuleDetailInfo>();
            TaskRuleDetailInfo taskRuleDetail = null;
            IDataReader reader = dataBase.ExecuteReader(tran, CommandType.Text, sql, paras);
            while (reader.Read())
            {
                DateTime CS00002;
                taskRuleDetail = new TaskRuleDetailInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["TASK_RULE_ID"].ToString(), (reader["LINE_ID"].ToString() != "") ? int.Parse(reader["LINE_ID"].ToString()) : 0, reader["TASK_STRATEGY"].ToString(), reader["DESCR"].ToString(), reader["TASK_TYPE"].ToString(), reader["TASK_TYPE_DESCR"].ToString(), reader["TASK_PICK_CODE"].ToString(), reader["IS_ACTIVE"].ToString(), (byte[]) reader["TS"], reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : (CS00002 = new DateTime()), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : (CS00002 = new DateTime()));
                taskRuleDetailInfos.Add(taskRuleDetail);
            }
            if (!reader.IsClosed)
            {
                reader.Close();
            }
            return taskRuleDetailInfos;
        }

        public int InsertTaskRuleDetail(TaskRuleDetailInfo taskRuleDetailInfo, List<string> whLoginID)
        {
            int result = 0;
            DataBase db = new DataBase();
            DbConnection conn = db.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    taskRuleDetailInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_TaskRuleDetail_Parameters(taskRuleDetailInfo);
                    if (paras != null)
                    {
                        result += db.ExecuteNonQuery(tran, CommandType.Text, this.SQL_INSERT_TASK_RULE_DETAIL.Replace("@_@", whLoginID[i]), paras);
                    }
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int InsertTaskRuleDetail(DataBase dataBase, DbTransaction tran, TaskRuleDetailInfo taskRuleDetailInfo, List<string> whLoginID)
        {
            int result = 0;
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    taskRuleDetailInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_TaskRuleDetail_Parameters(taskRuleDetailInfo);
                    if (paras != null)
                    {
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_INSERT_TASK_RULE_DETAIL.Replace("@_@", whLoginID[i]), paras);
                    }
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        private SqlParameter[] Set_TaskRuleDetail_Parameters(TaskRuleDetailInfo taskRuleDetailInfo)
        {
            SqlParameter[] paramArray = new SqlParameter[] { new SqlParameter(this.WH_ID, SqlDbType.VarChar, 30), new SqlParameter(this.TASK_RULE_ID, SqlDbType.VarChar, 20), new SqlParameter(this.LINE_ID, SqlDbType.Int, 4), new SqlParameter(this.TASK_STRATEGY, SqlDbType.VarChar, 20), new SqlParameter(this.DESCR, SqlDbType.VarChar, 100), new SqlParameter(this.TASK_TYPE, SqlDbType.VarChar, 20), new SqlParameter(this.TASK_PICK_CODE, SqlDbType.VarChar, 20), new SqlParameter(this.IS_ACTIVE, SqlDbType.VarChar, 1), new SqlParameter(this.CREATED_BY, SqlDbType.VarChar, 0x12), new SqlParameter(this.UPDATED_BY, SqlDbType.VarChar, 0x12) };
            if (!string.IsNullOrEmpty(taskRuleDetailInfo.WhID))
            {
                paramArray[0].Value = taskRuleDetailInfo.WhID;
            }
            else
            {
                paramArray[0].Value = DBNull.Value;
            }
            paramArray[1].Value = taskRuleDetailInfo.TaskRuleID;
            paramArray[2].Value = taskRuleDetailInfo.LineID;
            if (!string.IsNullOrEmpty(taskRuleDetailInfo.TaskStrategy))
            {
                paramArray[3].Value = taskRuleDetailInfo.TaskStrategy;
            }
            else
            {
                paramArray[3].Value = DBNull.Value;
            }
            paramArray[4].Value = taskRuleDetailInfo.Descr;
            paramArray[5].Value = taskRuleDetailInfo.TaskType;
            paramArray[6].Value = taskRuleDetailInfo.TaskPickCode;
            paramArray[7].Value = taskRuleDetailInfo.IsActive;
            paramArray[8].Value = taskRuleDetailInfo.CreatedBy;
            paramArray[9].Value = taskRuleDetailInfo.UpdatedBy;
            return paramArray;
        }

        public int UpdateTaskRuleDetail(TaskRuleDetailInfo taskRuleDetailInfo, List<string> whLoginID)
        {
            int result = 0;
            DataBase db = new DataBase();
            DbConnection conn = db.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    taskRuleDetailInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_TaskRuleDetail_Parameters(taskRuleDetailInfo);
                    if (paras != null)
                    {
                        result += db.ExecuteNonQuery(tran, CommandType.Text, this.SQL_UPDATE_TASK_RULE_DETAIL.Replace("@_@", whLoginID[i]), paras);
                    }
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int UpdateTaskRuleDetail(DataBase dataBase, DbTransaction tran, TaskRuleDetailInfo taskRuleDetailInfo, List<string> whLoginID)
        {
            int result = 0;
            try
            {
                for (int i = 0; i < whLoginID.Count; i++)
                {
                    taskRuleDetailInfo.WhID = whLoginID[i].Substring(0, whLoginID[i].Length - 1);
                    SqlParameter[] paras = this.Set_TaskRuleDetail_Parameters(taskRuleDetailInfo);
                    if (paras != null)
                    {
                        result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_UPDATE_TASK_RULE_DETAIL.Replace("@_@", whLoginID[i]), paras);
                    }
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }
    }
}

